//
//  YDOptionalEditingTableCell.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/14.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDOptionalEditingTableCell.h"

#import "YDOptionalStockModel.h"

@interface YDOptionalEditingTableCell()
//分割线
@property (nonatomic , weak) UIView *lineView;
//选择按钮
@property (nonatomic , weak) SYNoHeightedButton *selectedButton;
//股票名称
@property (nonatomic , weak) UILabel *stockName;
//置顶按钮
//@property (nonatomic , weak) SYNoHeightedButton *topButton;
@end


@implementation YDOptionalEditingTableCell

-(void)setModel:(YDOptionalStockModel *)model
{
    _model = model;
    self.selectedButton.selected = model.editingIsSelected;
    self.stockName.text = model.name;
    
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *optionalEditingTableCell = @"YDOptionalEditingTableCell";
    YDOptionalEditingTableCell *cell = [tableView dequeueReusableCellWithIdentifier:optionalEditingTableCell];
    if (cell == nil) {
        cell = [[YDOptionalEditingTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:optionalEditingTableCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];

        [self lineView];
        
        [self selectedButton];
        [self stockName];
        
       // [self topButton];
        
    }
    return self;
}

-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.height.equalTo(@1);
            make.left.equalTo(self).offset(rate375(23));
            make.right.equalTo(self).offset(-rate375(23));
        }];
        
        _lineView = lineView;
    }
    return _lineView;
}


-(SYNoHeightedButton *)selectedButton
{
    if (_selectedButton == nil) {
        SYNoHeightedButton *selectedButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
        [self.contentView addSubview:selectedButton];
        selectedButton.backgroundColor = [UIColor clearColor];
        [selectedButton setImage:[UIImage imageNamed:@"zixuan-duoxuan-weixuan"] forState:UIControlStateNormal];
        [selectedButton setImage:[UIImage imageNamed:@"zixuan-duoxuan-xuanzhong"] forState:UIControlStateSelected];
        [selectedButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@(rate375(20)));
            make.centerY.equalTo(self);
            make.left.equalTo(self).offset(rate375(23));
        }];

        [selectedButton addTarget:self action:@selector(selectedButtonClick:) forControlEvents:UIControlEventTouchDown];
        _selectedButton = selectedButton;
    }
    return _selectedButton;
}

-(void)selectedButtonClick:(SYNoHeightedButton *)button
{
    if ([_delegate respondsToSelector:@selector(optionalEditingTableCellDidClickSelected:)]) {
        [_delegate optionalEditingTableCellDidClickSelected:self];
    }
}

-(UILabel *)stockName
{
    if (_stockName == nil) {
        UILabel *stockName = [[UILabel alloc] init];
        [self.contentView addSubview:stockName];
        stockName.textColor = [UIColor colorWithHexString:dark];
        stockName.font = [UIFont systemFontOfSize:font20ScreenWRate * LKScreenW];
        stockName.textAlignment = NSTextAlignmentLeft;
        stockName.text = @"万科a";
        [stockName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.selectedButton.mas_right).offset(rate375(8.5));
            make.centerY.equalTo(self);
        }];
        _stockName = stockName;
    }
    return _stockName;
}


//-(SYNoHeightedButton *)topButton
//{
//    if (_topButton == nil) {
//        SYNoHeightedButton *topButton = [SYNoHeightedButton buttonWithType:UIButtonTypeCustom];
//        [self.contentView addSubview:topButton];
//        topButton.backgroundColor = [UIColor clearColor];
//        [topButton setImage:[UIImage imageNamed:@"zixuan-zhiding"] forState:UIControlStateNormal];
//        [topButton mas_makeConstraints:^(MASConstraintMaker *make) {
////            make.width.height.equalTo(@(rate375(20)));
//            make.centerY.equalTo(self);
//            make.right.equalTo(self).offset(-rate375(43));
//        }];
//
//        [topButton addTarget:self action:@selector(topButtonClick:) forControlEvents:UIControlEventTouchDown];
//        _topButton = topButton;
//    }
//    return _topButton;
//}

//-(void)topButtonClick:(SYNoHeightedButton *)button
//{
//    if ([_delegate respondsToSelector:@selector(optionalEditingTableCellDidClickTopButton:)]) {
//        [_delegate optionalEditingTableCellDidClickTopButton:self];
//    }
//}

@end
